package com.example.controller.shopping;

import cn.hutool.core.date.DateUtil;
import com.example.common.Result;

import com.example.common.enums.ResultCodeEnum;
import com.example.common.enums.RoleEnum;
import com.example.exception.CustomException;
import com.example.model.entity.appointment.User;
import com.example.model.entity.medical.Doctor;
import com.example.model.entity.other.Account;
import com.example.model.entity.shopping.Cart;
import com.example.model.entity.shopping.Medicines;
import com.example.model.entity.shopping.Order;
import com.example.model.vo.OrderVO;
import com.example.service.shopping.OrderService;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * 药物订单表前端操作接口
 **/
@RestController
@RequestMapping("/order")
@Api(tags = "药物订单接口")
public class OrderController {

    @Resource
    private OrderService orderService;

    /**
     * 直接下单
     */
    @PostMapping("/pay")
    public Result pay(@RequestBody Order order) throws ParseException {
        orderService.pay(order);
        return Result.success();
    }
    /**
     * 新增
     */
    @ApiOperation(value = "新增药物订单")
    @PostMapping("/add")
    public Result add(@RequestBody Order order) throws ParseException {
        orderService.add(order);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除药物订单")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        orderService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除药物订单")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        orderService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改药物订单")
    @PutMapping("/update")
    public Result updateById(@RequestBody Order order) throws ParseException {
        orderService.updateById(order);
        return Result.success();
    }
    /**
     * 修改
     */
    @ApiOperation(value = "支付药物")
    @PutMapping("/updatePay")
    public Result updatePay(@RequestBody Order order) throws ParseException {
        orderService.updatePay(order);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询药物订单")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Order order = orderService.selectById(id);
        return Result.success(order);
    }

    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有药物订单")
    @GetMapping("/selectAll")
    public Result selectAll(Order order) {
        List<OrderVO> list = orderService.selectAll(order);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询药物订单")
    @GetMapping("/selectPage")
    public Result selectPage(Order order,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<OrderVO> page = orderService.selectPage(order, pageNum, pageSize);
        return Result.success(page);
    }

}
